package com.example.dishfo.myapplication.customview.mydialog;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.FloatRange;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.example.dishfo.myapplication.R;

public class WaitDialogFragment extends DialogFragment {

    private String textWait;
    private DialogInterface.OnDismissListener dismissListener;

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());
        LayoutInflater inflater=getActivity().getLayoutInflater();
        View view=inflater.inflate(R.layout.dialog_progress_wait,null);
        ((TextView)view.findViewById(R.id.textview1)).setText(textWait);
        builder.setView(view);
        Dialog dialog=builder.create();
        dialog.setCanceledOnTouchOutside(false);
        if(dismissListener!=null)
            dialog.setOnDismissListener(dismissListener);
        return dialog;
    }


    public static WaitDialogFragment getInstance(String arg){
        WaitDialogFragment fragment=new WaitDialogFragment();
        fragment.textWait=arg;
        fragment.setCancelable(true);

        return fragment;
    }

    public static WaitDialogFragment getInstance(String arg,
                                                 DialogInterface.OnDismissListener dismissListener){
        WaitDialogFragment fragment=new WaitDialogFragment();
        fragment.textWait=arg;
        fragment.dismissListener=dismissListener;
        fragment.setCancelable(true);
        return fragment;
    }

    @Override
    public void onStop() {
        super.onStop();
        dismissListener.onDismiss(null);
    }
}
